package com.ruicar.afs.cloud.channel.drawerparty.controller;

import com.ruicar.afs.cloud.channel.common.feign.ChannelUseCaseService;
import com.ruicar.afs.cloud.channel.common.until.ChannelConfig;
import com.ruicar.afs.cloud.channel.drawerparty.condition.DrawerPartyCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: sang jian
 * @date: 2020/6/18 9:57
 * @description:
 */
@RestController
@Api("渠道调案件开票方接口")
@RequestMapping("/drawerParty")
public class DrawerPartyController {

    @Autowired
    private ChannelUseCaseService channelUseCaseService;

    @Autowired
    private ChannelConfig channelConfig;


    @PostMapping("/getByCondition")
    @ApiOperation(value = "多条件分页获取开票方")
    public IResponse getDrawerPartys(@RequestBody DrawerPartyCondition condition) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.getDrawerPartys(condition, headers);

    }

    @GetMapping("/getDrawerPartyById/{id}/{carDealerId}")
    @ApiOperation(value = "根据开票方id查询基本信息")
    public IResponse getDrawerPartyById(@PathVariable String id, @PathVariable String carDealerId) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.getDrawerPartyById(id, carDealerId, headers);
    }

    @GetMapping("/disableDrawerParty/{ids}")
    @ApiOperation(value = "禁用开票方")
    public IResponse disableDrawerParty(@PathVariable String[] ids) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.disableDrawerParty(ids, headers);
    }

    @DeleteMapping("/delByIds/{id}")
    @ApiOperation(value = "删除开票方")
    public IResponse deleteById(@PathVariable String id) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.deleteById(id, headers);
    }

    @GetMapping("/getCarDealerByChannelId/{id}")
    @ApiOperation(value = "根据渠道id查询车商信息")
    public IResponse getCarDealerByChannelId(@PathVariable String id) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.getCarDealerByChannelId(id, headers);
    }

    @PostMapping("/saveOrUpdateDrawerParty")
    @ApiOperation(value = "新增或更新开票方")
    public IResponse saveOrUpdateDrawerParty(@RequestBody DrawerPartyCondition condition) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.saveOrUpdateDrawerParty(condition, headers);
    }

    @PostMapping("/getDrawerPartyByChannel")
    @ApiOperation(value = "查询合作商下的开票方列表")
    public IResponse getDrawerPartyByChannel(@RequestBody DrawerPartyCondition condition) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.getDrawerPartyByChannel(condition, headers);
    }

    @PostMapping("/getAllSPChannels")
    @ApiOperation(value = "查询所有的SP和总对总")
    public IResponse getAllSPChannels( @RequestBody DrawerPartyCondition condition) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("clientId", channelConfig.getCaseClientId());
        headers.put("clientSecret", channelConfig.getCaseClientId());
        return channelUseCaseService.getAllSPChannels(condition,headers);
    }


}
